﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using WHControlLib.CommonHelpers;
using WHControlLib.Controls;

namespace WHControlLib.Controls
{
    [ToolboxItem(true)]
        [DefaultEvent("OKButtonCLick")]
    public partial class WHNumKeyBoard : UserControl
    {
       
        public WHNumKeyBoard()

        {
        


            InitializeComponent();

        }


        private Color _myFontColor=Color.Black
            ;
        [Category("A我的"), Description("按钮字体的颜色，默认 黑色"), Browsable(true)]
        public Color MyFontColor
        {
            get { return _myFontColor; }
            set
            {
                foreach (var item in WHPanel1.Controls)
                {
                    if (item is WHButton)
                    {
                        WHButton w = (WHButton)item;
                        w.FontColor = value;
                    }
                }
                WBTDel.IconFontColor = value;
                  _myFontColor = value;
                Invalidate();

            }
        }

        private Color _myButtonColor = Color.Orange;
        [Category("A我的"), Description("按钮背景的颜色，默认 橙色"), Browsable(true)]

        public Color MyButtonColor
        {
            get { return _myButtonColor; }
            set
            {
                foreach (var item in WHPanel1.Controls)
                {
                    if (item is WHButton)
                    {
                        WHButton w = (WHButton)item;
                        w.FirstFillcolor = value;
                    }
                }
                _myButtonColor = value;
                Invalidate();

            }
        }

      


        private string _okButtonText="确定";
        [Category("A我的"), Description("OK按钮的文字，默认 确定"), Browsable(true)]
        public string OKButtonText
        {
            get { return _okButtonText; }
            set
            {
                if (value!=null)
                {
                WBTOK.Text = value;
                }
                else WBTOK.Text = "确定";

                _okButtonText = value; }
        }

      

     

        private Color _myButtonOnMouseColor=Color.DarkOrange;
        [Category("A我的"), Description("鼠标经过按钮的颜色，默认 深橙色"), Browsable(true)]
        public Color MyButtonOnMouseColor
        {
            get { return _myButtonOnMouseColor; }
            set {
                foreach (var item in WHPanel1.Controls)
                {
                    if (item is WHButton)
                    {
                        WHButton wb = item as WHButton;
                        if (wb!=null)
                        {
                            wb.OnMouseColor= value;

                        }
                          
                    }
                }
                 _myButtonOnMouseColor = value; }
        }


        private int _delImageSize=25;
        [Category("A我的"), Description("删除图标大小，默认 25f"), Browsable(true)]
        public int DelImageSize
        {
            get { return _delImageSize; }
            set
            {
                if (value>2)
                {
                    WBTDel.IconFontSize = value;

                }
                
                _delImageSize = value; }
        }

        private bool _isShowBorder;
        [Category("A我的"), Description("是否显示控件边框，默认 是"), Browsable(true)]
        public bool IsShowBorder
        {
            get { return _isShowBorder; 
            }
            set
            {
                WHPanel1.IsShowBorder = value;
                 _isShowBorder = value; 
                Invalidate();
            }
        }

        private Color _borderColor=Color.Blue;
        [Category("A我的"), Description("控件边框颜色，默认 蓝色"), Browsable(true)]
        public Color BorderColor
        {
            get { return _borderColor; }
            set {
                WHPanel1.BorderColor = value; 
                 _borderColor = value; Invalidate();
            }
        }

        private bool _isShowButtonBorder=true;
        [Category("A我的"), Description("是否显示控件按钮边框，默认 否"), Browsable(true)]
        public bool IsShowButtonBorder
        {
            get
            {
                return _isShowButtonBorder;
            }
            set
            {

                foreach (var item in WHPanel1.Controls)
                {
                    if (item is WHButton)
                    {
                        WHButton w = (WHButton)item;
                        w.IsDrawBoin = value;
                    }
                }



                _isShowButtonBorder = value; Invalidate();
            }
        }

        private Color _buttonBorderColor = Color.Red;

        [Category("A我的"), Description("控件按钮边框颜色，默认 蓝色"), Browsable(true)]
        public Color ButtonBorderColor

        {
            get { return _buttonBorderColor; }
            set
            {

                foreach (var item in WHPanel1.Controls)
                {
                    if (item is WHButton)
                    {
                        WHButton w = (WHButton)item;
                        w.BornColor = value;
                    }
                }


                _buttonBorderColor = value;
                Invalidate();

            }
        }

        private Color _myBackColor=Color.Tan;
        [Category("A我的"), Description("控件背景色颜色，默认 浅橙色色"), Browsable(true)]
        public Color MyBackColor
        {
            get { return _myBackColor; }
            set {
                 WHPanel1.FirstFillcolor= value;
                _myBackColor = value; Invalidate();
            }
        }


        private Font _myFont = new Font("微软雅黑", 12.0f, 0, GraphicsUnit.Point, 1);
[Category("A我的"), Description(" 控件字体，默认 微软雅黑12t"), Browsable(true)]
public Font MyFont
{
    get { return _myFont; }
    set {
        foreach (var item in WHPanel1.Controls)
        {
            if (item is WHButton)
            {
                WHButton w = (WHButton)item;
                w.MyFont = value;
            }
        }
        _myFont = value;
        this.Invalidate(); }
}



[Category("A我的事件"), Description("当本控件的确定按钮按下发生"), Browsable(true)]



        public event EventHandler OKButtonCLick;
                                                                      




        private void WBT00_Paint(object sender, PaintEventArgs e)
        {

        }
   
        private void WHNumTouchKey_Load(object sender, EventArgs e)
        {
          

        }




        private void WBT1_MouseDown(object sender, MouseEventArgs e)
        {
         
            SendKeys.Send("{1}");
       
;
        }

        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            SendKeys.Send("{1}");
        }

        private void WBT1_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{1}");

        }

  

        private void WBT2_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{2}");
        }



        private void WBT3_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{3}");
        }

        private void WBTDel_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{BACKSPACE}");
        }

        private void WBTClear_Click(object sender, EventArgs e)
        {
            SendKeys.SendWait("^a");
            SendKeys.Send("{BACKSPACE}");

        }

        private void WBTOK_Click(object sender, EventArgs e)
        {
            if (OKButtonCLick!=null)
            {
                  this.Invoke( new Action(()=>OKButtonCLick(sender, e))   )    ;
            }
           
                  

        }

        private void WBT4_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{4}");

        }

        private void WBT5_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{5}");
        }

        private void WBT6_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{6}");
        }

        private void WBT7_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{7}");
        }

        private void WBT8_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{8}");
        }

        private void WBT9_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{9}");

        }

        private void WBT00_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{0}");
            SendKeys.Send("{0}");
        }

        private void WBT0_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{0}");
        }

        private void WBTdot_Click(object sender, EventArgs e)
        {
            SendKeys.Send("{.}");
        }
        
        void ResizeButton(WHButton wb,int H, int V)
        {
            int BtWidth, BtHeight;
            BtWidth = WHPanel1.Width /5;
            wb.Width = BtWidth;
            BtHeight= WHPanel1.Height /5;
             wb .Height= BtHeight;
            Point p = new Point();
            p.X=WHPanel1.Location.X+WHPanel1.Width/25* V + BtWidth*(V-1);
              
            p.Y= WHPanel1.Location.Y + WHPanel1.Height / 25* H + BtHeight*(H-1);
            wb.Location = p;
          

        }
        private void WHNumKeyBoard_Resize(object sender, EventArgs e)
        {
          


        }

        private void WBT1_Resize(object sender, EventArgs e)
        {
           
        }

        private void WBT2_Resize(object sender, EventArgs e)
        {
          
        }

        private void WBT3_Resize(object sender, EventArgs e)
        {
        
        }

        private void WBTDel_Resize(object sender, EventArgs e)
        {
        }

        private void WHPanel1_Resize(object sender, EventArgs e)
        {
            ResizeButton(WBT1, 1, 1);

            ResizeButton(WBT2, 1, 2);

            ResizeButton(WBT3, 1, 3);
            ResizeButton(WBTDel, 1, 4);
            ResizeButton(WBT4, 2, 1);

            ResizeButton(WBT5, 2,2 );
            ResizeButton(WBT6, 2, 3);

            ResizeButton(WBTClear, 2, 4);

            ResizeButton(WBT7, 3, 1);

            ResizeButton(WBT8, 3, 2);
            ResizeButton(WBT9, 3, 3);

            ResizeButton(WBT00, 4, 1);
            ResizeButton(WBT0, 4, 2);
            ResizeButton(WBTdot, 4, 3);

            WBTOK.Width = Width / 5;
            WBTOK.Height = Height / 5*2 + WHPanel1.Height / 25;
            Point pp = new Point();
            pp.Y = WBTClear.Bottom + WHPanel1.Height / 25;
            pp.X = WBT9.Right + WHPanel1.Width / 25;
            WBTOK.Location = pp;
                                


        }
    }
}
